import React, { FC, useContext, useState } from 'react';
import { Button, Select } from 'antd';
import JSZip from 'jszip';
import saveAs from 'file-saver';

import { getIndexText, getServiceText, getModelText } from './tpl';
const DownCode: FC<any> = (props: any) => {
  // 下载源码
  const onClickDownCode = () => {
    let zip = new JSZip();
    zip.file('index.tsx', getIndexText());
    let models = zip.folder('models');
    // to
    models?.file('index.ts', getModelText());
    let services = zip.folder('services');
    services?.file('index.ts', getServiceText());
    zip.folder('components');

    // 下载文档
    zip.generateAsync({ type: 'blob' }).then(function (content) {
      // see FileSaver.js
      saveAs(content, 'NodeCom.zip');
    });
  };

  return <Button onClick={onClickDownCode}>下载源码</Button>;
};

export default DownCode;
// todo 添加可以拖拽属性
